#ifndef __FW_FONTCACHE_H__
#define __FW_FONTCACHE_H__

namespace freewrite
{

struct AllocationToken;

class FontCache
{
	FW_NO_COPYCONSTRUCT(FontCache);

private:
	IFWTextureFactory* m_TextureFactory;
	FontLibraryImpl* m_Library;
	std::vector<FontMap*> m_FontMaps;
	std::map<std::string, Font*> m_LoadedFonts;
	std::string m_DefaultFontName;

	bool Alloc(Character* chr, AllocationToken* token);
	bool WriteBitmap(uint8_t* pSrc, uint32_t srcPitch, uint32_t width, uint32_t height, AllocationToken* token, bool bDoNotWait);
	
	friend class Font;
	friend struct Character;

public:
	Font* LoadFont(const std::string& fontName);
	void Defragment();

	//If a character is missing in the given font, then use this one for 'backup'.
	void SetDefaultFont(const std::string& defaultFont);
	Font* GetDefaultFont()
	{
		auto itor = m_LoadedFonts.find(m_DefaultFontName);
		if(itor != m_LoadedFonts.end())
		{
			return itor->second;
		}
		return nullptr;
	}

	FontCache(IFWTextureFactory* pTexFactory);
	~FontCache();

	bool Initialize();
	void CleanUp();
};

}

#endif//__FW_FONTCACHE_H__